{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys  ###policyevaluation1\n",
    "sys.path.append('../scripts/')\n",
    "from puddle_world import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "class PolicyEvaluator:\n",
    "    def __init__(self, widths, lowerleft=np.array([-4, -4]).T, upperright=np.array([4, 4]).T):\n",
    "        self.pose_min = np.r_[lowerleft, 0]\n",
    "        self.pose_max = np.r_[upperright, math.pi*2] #thetaの範囲0〜2πで固定\n",
    "        self.widths = widths\n",
    "        \n",
    "        self.index_nums = ((self.pose_max - self.pose_min)/self.widths).astype(int)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[40 40 36]\n"
     ]
    }
   ],
   "source": [
    "pe = PolicyEvaluator(np.array([0.2, 0.2, math.pi/18]).T) #PolicyEvaluatorのオブジェクトを生成\n",
    "print(pe.index_nums)  #区間の個数を表示"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 0 0]\n",
      "[34 10 18]\n",
      "[-5 10  3]\n"
     ]
    }
   ],
   "source": [
    "#様々な座標のインデックスを求めてみましょう\n",
    "\n",
    "pose = np.array([-4, -4, 0]).T\n",
    "print( np.floor((pose - pe.pose_min)/pe.widths).astype(int) )\n",
    "\n",
    "pose = np.array([2.9, -2, math.pi]).T\n",
    "print (np.floor((pose - pe.pose_min)/pe.widths).astype(int) )\n",
    "\n",
    "pose = np.array([-5, -2, math.pi/6]).T\n",
    "print (np.floor((pose - pe.pose_min)/pe.widths).astype(int) )"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
